#!/usr/bin/env python

"""
docstring
"""

from datetime import tzinfo
from datetime import timedelta
import re

class Timezone(tzinfo):
    def __init__(self, offset='00:00'):
        flag = True
        hour = 0
        min = 0
        match = re.match('^([+|-])?([0-9]{2}):([0-9]{2})$', offset)
        format_error_message = 'Invalid offset which should be [+/-]HH:MM. HH must between 00~12, MM must between 00~59' 
        if None == match:
            raise ValueError(format_error_message)
        
        groups = match.groups()
        if None != groups[0] and '-' == groups[0]:
            flag = False
        if None != groups[1]:
            hour = int(groups[1])
            if hour > 12:
                raise ValueError(format_error_message)

        if None != groups[2]:
            min = int(groups[2])
            if min > 59:
                raise ValueError(format_error_message)

        if not flag:
            hour *= -1
            min *= -1
        self.delta = timedelta(hours = hour, minutes = min)
        self.name = 'GMT'
        if hour != 0:
            if '-' != groups[0]:
                self.name += '+'
            self.name += str(hour)

    def utcoffset(self, tc=None):
        return self.delta

    def dst(self, tc=None):
        pass

    def tzname(self, tc=None):
        return self.name
